﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace MyQQ
{
    class DataOperator
    {
        //定义数据库连接字符串
        private static string connString = "Data Source=(local);DataBase=db_MyQQ;UID=;Pwd=;";
        //定义数据库连接对象
        public static SqlConnection connecton = new SqlConnection(connString);

        //操作数据库的方法
        public int ExecSQL(string sql)
        {
            SqlCommand command = new SqlCommand(sql, connecton);//指定要执行的SQL语句
            if (connecton.State == ConnectionState.Closed)
                connecton.Open();
            int num = Convert.ToInt32(command.ExecuteScalar());
            connecton.Close();
            return num;
        }        
        
        public int ExecSQLResult(string sql)
        {
            SqlCommand command = new SqlCommand(sql, connecton);//指定要执行的SQL语句
            if (connecton.State == ConnectionState.Closed)
                connecton.Open();
            int result = Convert.ToInt32(command.ExecuteNonQuery());
            connecton.Close();
            return result;
        }
    }
}
